package com.neiru.divider.dao.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.neiru.divider.dao.constants.Constants;
import com.neiru.divider.dao.constants.LevelConstants;
import com.neiru.divider.dao.constants.PlayerConstants;

public class DatabaseHelper extends SQLiteOpenHelper {

	private static final String TAG = "DatabaseHelper";
	private Context context;
	public DatabaseHelper(Context context) {
		super(context, Constants.DATABASE_NAME, null,
				Constants.DATABASE_VERSION);
		this.context = context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(PlayerConstants.DATABASE_PLAYER_TABLE_CREATE);
		db.execSQL(LevelConstants.DATABASE_LEVELS_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
				+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + PlayerConstants.DATABASE_PLAYER_TABLE);
		db.execSQL("DROP TABLE IF EXISTS " + LevelConstants.DATABASE_LEVELS_TABLE);
		onCreate(db);
	}

}
